package tp.pr5.commands;

import tp.pr5.Game;
import tp.pr5.Map;
import tp.pr5.MensajesConst;
import tp.pr5.Player;
import tp.pr5.commands.exceptions.CommandExecutionException;
import tp.pr5.commands.exceptions.WrongCommandFormatException;

public class LookCommand implements Command
{

	
	String _cad;
	private Player _friki;

	public LookCommand()
	{

	}
	public void configureContext(Game g, Map m, Player p) {
		this._friki=p;
	
	}
	public LookCommand(String item, Player pers)
	{
		this._cad = item;
		this._friki = pers;
	}

	public LookCommand(Player pers)
	{
		this._friki = pers;
		this._cad = null;
	}

	@Override public void execute() throws CommandExecutionException
	{
		// TODO Auto-generated method stub
		if (this._cad == null)
		{
			this._friki.requestLookInventory();//System.out.println(this._friki.showItems());
		}
		else
		{
			if (this._friki.getItem(_cad) == null)
				throw new CommandExecutionException("There is no " + this._cad
						+ " in your inventory.\n");
			else 
				this._friki.lookItem(_cad);
			//	System.out.println(this._friki.getItem(_cad));
		}

	}

	@Override public String getHelp()
	{
		// TODO Auto-generated method stub
		return MensajesConst.hLook;
	}

	@Override public Command parse(String cad)
			throws WrongCommandFormatException
	{
		String cadena[] = cad.split(" ");

		if (cadena.length < 1 || cadena.length > 2)
			throw new WrongCommandFormatException();
		if (!(cadena[0].equalsIgnoreCase("look") || cadena[0]
				.equalsIgnoreCase("mira")))
			throw new WrongCommandFormatException();
		if (cadena.length == 1)
			return new LookCommand(this._friki);
		return new LookCommand(cadena[1], this._friki);
	}
}
